﻿chrome.webRequest.onBeforeRequest.addListener(
    function (request) {
        var ajax = localStorage["ajax.googleapis.com"] || 'ajax.loli.net';
        var fonts = localStorage["fonts.googleapis.com"] || 'fonts.loli.net';
        var url = request.url.replace(/^(\w+?):\/\/(\w+?)\.googleapis\.com(.+)/i, function (arg, arg1, arg2, arg3) {
            return arg1 + '://' + (arg2 == 'ajax' ? ajax : fonts) + arg3;
            // return arg1 + t + arg3;
        });
        return { redirectUrl: url };
    },
    {
        urls: [
            "*://ajax.googleapis.com/*",
            "*://fonts.googleapis.com/*"
        ]
    },
    ["blocking"]
);
